part of base.temples;

abstract class LeftTabState<W extends StatefulWidget> extends State<W> {
  List<LeftTabOption> getTabOptions();

  void setTabSelect(int index);

  int tabIndex = 0;

  get navItems =>
      this.getTabOptions().map((child) => child.navigationBarItem).toList();

  get child => this.getTabOptions().map((child) => child.children).toList();

  get _bar => NavigationRail(
        backgroundColor: KColors.primaryColor,
        selectedIndex: tabIndex,
        labelType: NavigationRailLabelType.all,
        destinations: navItems,
        minWidth: 30.w,
        onDestinationSelected: (index) {
          setState(() {
            if (tabIndex != index) {
              tabIndex = index;
              setTabSelect(tabIndex);
            }
          });
        },
      );

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        LayoutBuilder(builder: (context, constraint) {
          return SingleChildScrollView(
              child: ConstrainedBox(
                  constraints: BoxConstraints(minHeight: constraint.maxHeight),
                  child: IntrinsicHeight(child: _bar)));
        }),
        VerticalDivider(thickness: 1, width: 1),
        Expanded(
          child: IndexedStack(
            children: child,
            index: tabIndex,
          ),
        )
      ],
    );
  }
}

class LeftTabOption {
  LeftTabOption(
      {required this.children,
      required this.navigationBarItem,
      required this.tabIndex});

  Widget children;
  NavigationRailDestination navigationBarItem;
  int tabIndex;
}
